/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * alumnodesemestre.java
 *
 * Created on 23-oct-2011, 20:01:25
 */

package proyectocatalina.mantenimiento;

import CapadeDatos.daolistadoalumnos2;
import CapadeDatos.daosemestreunidad;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.table.DefaultTableModel;
import modelo.beanlista;
import modelo.beansemestre;


public class alumnosdesemestre extends javax.swing.JInternalFrame {
String codsem;
int x=-1;
int a,b;

    /** Creates new form alumnodesemestre */
    public alumnosdesemestre() {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        a=semestre_unidad.y;
        b=newsemestreunidad.y;
 if(a==2)x=1;else if(b==1) x=2;

switch (x)
{
    case 1:codsem=semestre_unidad.coddelistado;break;

    case 2:codsem=newsemestreunidad.codlistado;break;
    default:codsem="S-1";
    }

if(codsem==null||codsem.isEmpty())codsem="S-1";
    
   tablaalumnos();
    }
    beanlista detalles[];
    private  void tablaalumnos(){


         beansemestre semestre=new beansemestre();//recipiente de la info de alumno

      semestre= (beansemestre)daosemestreunidad.semestre(codsem);//recoger datos de alum


     jtxtcarr.setText(semestre.getCod_carrera());//mostar info de sem

     jtxtperlect.setText(semestre.getCod_per());

    jtxtsem.setText(semestre.getDescipcion()) ;
     jtxtturno.setText(semestre.getTurno());
     jtxtini.setText(semestre.getFechaini());
     jtxtfin.setText(semestre.getFechafin());
     jtxtestado.setText(semestre.getEstado());




    ArrayList alumnos=new ArrayList();//recipiente de  array

alumnos = (ArrayList)daolistadoalumnos2.listadoalumnosxsem(codsem);//recoger array de semestre q estuvo


      detalles = new beanlista[alumnos.size()];//armado y llenado de la 1º tabla que se llama jtable2
          Iterator itr = alumnos.iterator();
      int j=0;

      DefaultTableModel dtm = null;

//JOptionPane.showMessageDialog(null," "+detalles[0].getCod_carrera()+"  "+detalles[0].getCod_sem());


dtm =(DefaultTableModel) jtable1.getModel();
      for (int i = jtable1.getRowCount() -1; i >= 0; i--){
dtm.removeRow(i);
}//borrar las lineas de tabla para
//la prox que llame a este codigo
           while (itr.hasNext()) {
          detalles[j] =  (beanlista)itr.next();
          Object[] newRow={detalles[j].getCodalumno(),
          detalles[j].getApepat()+" "+detalles[j].getApemat(),
          detalles[j].getNombre(),
          detalles[j].getDni(),
          detalles[j].getCarrera(),
          detalles[j].getTurno(),
          detalles[j].getFechadetmatri(),
          detalles[j].getUnidadesrep()
          };
           dtm =(DefaultTableModel) jtable1.getModel(); // Obtenemos el modelo por defecto de la tabla
           dtm.addRow(newRow); // añadimos la fila
          j++;
      }

      jtable1.setModel(dtm);


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jtable1 = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        jtxtcarr = new javax.swing.JTextField();
        jtxtsem = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jtxtini = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jtxtfin = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtxtperlect = new javax.swing.JTextField();
        jtxtturno = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jtxtestado = new javax.swing.JTextField();
        jbtnchangeestado = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);

        jtable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "codmatricula", "Apellidos", "Nombres", "DNI", "Carrera del Alumno", "TURNO", "Fecha de matricula en el semestre", "Unid. Rep"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jtable1);

        jLabel4.setText("CARRERA :");

        jtxtcarr.setEnabled(false);

        jtxtsem.setEnabled(false);

        jLabel5.setText("SEMESTRE :");

        jLabel11.setText("Fecha de Inicio:");

        jtxtini.setEnabled(false);

        jLabel12.setText("Fecha de Fin:");

        jtxtfin.setEnabled(false);

        jLabel6.setText("PER. LECTIVO :");

        jtxtperlect.setEnabled(false);

        jtxtturno.setEnabled(false);

        jLabel7.setText("TURNO :");

        jLabel13.setText("Estado:");

        jtxtestado.setEnabled(false);

        jbtnchangeestado.setText("Cambiar de Estado");
        jbtnchangeestado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnchangeestadoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel11))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jtxtsem)
                        .addComponent(jtxtcarr, javax.swing.GroupLayout.PREFERRED_SIZE, 410, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jtxtestado, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxtini, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jbtnchangeestado, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addGap(18, 18, 18)
                                .addComponent(jtxtfin, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel6))
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jtxtturno)
                    .addComponent(jtxtperlect, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addContainerGap(754, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 801, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtcarr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtsem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtini, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)
                            .addComponent(jtxtfin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtperlect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtturno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(jLabel13))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtnchangeestado)
                        .addComponent(jtxtestado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnchangeestadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnchangeestadoActionPerformed
        beansemestre semestre;
        String cod_sem;
        String estado;
        cod_sem=codsem;
        estado=jtxtestado.getText();
        CapadeDatos.daosemestreunidad k =new daosemestreunidad();

        k.cambiarestadosemestre(cod_sem,estado);


        semestre= (beansemestre)daosemestreunidad.semestre(cod_sem);//recoger datos de alum

        jtxtestado.setText(semestre.getEstado());


        // TODO add your handling code here:
}//GEN-LAST:event_jbtnchangeestadoActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new alumnosdesemestre().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnchangeestado;
    private javax.swing.JTable jtable1;
    private javax.swing.JTextField jtxtcarr;
    private javax.swing.JTextField jtxtestado;
    private javax.swing.JTextField jtxtfin;
    private javax.swing.JTextField jtxtini;
    private javax.swing.JTextField jtxtperlect;
    private javax.swing.JTextField jtxtsem;
    private javax.swing.JTextField jtxtturno;
    // End of variables declaration//GEN-END:variables

}
